package com.qf.service.impl;

import com.qf.mapper.DtsCategoryMapper;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.CategorySellVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lixu
 */
@Service
public class DtsCategoryServiceImpl implements DtsCategoryService {

    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;
    /**
     * 商品分类和对应分类的销售额
     * @return
     */
    @Override
    public CategorySellVo findCategorySellVo() {
        CategorySellVo categorySellVo = new CategorySellVo();
        List<CategorySellAmts> categorySellAmtsList  =
                dtsCategoryMapper.findCategorySellVo();
        categorySellVo.setCategorySellData(categorySellAmtsList);
        //Stream  偷天换日 原来是对象 现在是数组
        List<String> collect = categorySellAmtsList.stream().map(CategorySellAmts::getName).collect(Collectors.toList());
        categorySellVo.setCategoryNames(collect);
        return categorySellVo;
    }
}
